/*
 * @Author: scl
 * @Date: 2023-09-18 22:52:34
 * @LastEditTime: 2023-09-19 00:35:28
 * @Description: file content
 */
import { http } from "@/utils/http"
import type { CartItem } from "@/types/cart"
/**
 * 加入购物车
 * @param data 请求体参数
 */
export const postMemberCartAPI = (data: { skuId: string, count: number }) => {
    return http({
        url: "/member/cart",
        method: "POST",
        data
    })
}
/** 获取购物车列表*/
export const getMemberCartAPI = () => {
    return http<CartItem[]>({
        url: "/member/cart",
        method: "GET"
    })
}
/** 
 * 删除/清空购物车单品
 * @param data 请求体参数 ids SKUID 集合
 */
export const deleteMemberCartAPI = (ids: string[]) => {
    return http({
        url: "/member/cart",
        method: "DELETE",
        data: { ids }
    })
}

/**
 * 修改购物车单品
 * @param skuId SKUID
 * @param data selected 选中状态 count 商品数量
 */
export const putMemberCartBySkuIdAPI = (SkuId: string, data: { selected?: boolean, count?: number }) => {
    return http({
        url: `/member/cart/${SkuId}`,
        method: "PUT",
        data
    })
}
/**
 * 购物车全选/取消全选
 * @param data selected 是否选中
 */
export const putMemberCartSelectedAPI = (data: { selected: boolean }) => {
    return http({
        method: 'PUT',
        url: '/member/cart/selected',
        data,
    })
}